public class NumberCategory {

    public static void main(String[] args) {
        int range = 1000;

        getPerfectNum(range);
    }
    /**
     * 返回range以内的所有完数
     * @param range
     * @return
     */
    public static void getPerfectNum(int range) {

        for (int i = 1; i< range; i++) {

            if (i > range) {
                break;
            }

            if (isPerfectNum(i)) System.out.println(i + "是完数");
        }
    }

    /**
     * 是否为完数
     * @return
     */
    public static boolean isPerfectNum(int num) {

        int s = 0;
        for (int i = 1; i< num; i++) {
            if (num % i == 0) {
                s += i;
            }
        }

        if(s == num) return true;
        else return false;
    }
}
